/**
 * 
 */
package com.module.bp.event.base;

import com.module.bp.condition.Condition;

/**
 * The base class upon which all {@link Event} subclasses are derived.
 * @author DaLoneDrau
 */
public abstract class BaseEvent implements Event {
	private static int nextId = 0;
	private int id;
	/**
	 * Creates a new instance of {@link BaseEvent}.
	 */
	public BaseEvent() {
		id = nextId++;
	}
	public int getId() {
		return id;
	}
	/** the {@link Condition} tied to this {@link BaseEvent}. */
	private Condition	condition;
	/** flag indicating the {@link Event} was fired. */
	private boolean		fired;
	/** flag indicating the {@link BaseEvent} has been resolved. */
	private boolean		resolved	= false;
	/**
	 * {@inheritDoc}
	 */
	@Override
	public final Condition getCondition() {
		return condition;
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public final boolean happens() {
		boolean happens = true;
		if (condition != null) {
			if (!condition.passes()) {
				happens = false;
			}
		}
		return happens;
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public final boolean isResolved() {
		return resolved;
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public final void reset() {
		resolved = false;
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public final void setCondition(final Condition c) {
		condition = c;
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public final void setFired(final boolean val) {
		fired = val;
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public final void setResolved(final boolean val) {
		System.out.println("*********RESOLVED "+val+"::"+this);
		resolved = val;
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public final boolean wasFired() {
		return fired;
	}
}
